def func01():
    print("开始")
    yield "01"  # yield后面是生成的数据，有多少个yield就能生成多少条数据，yield只能在函数中使用
    print("结束")
    yield "02"
    print("再来一次")


def fun02():
    for i in range(100):
        s = yield i


def fun03():
    res = {"data": None}
    for i in range(100):
        s = yield res
        res["data"] = s


# print()
# res = func01()
# print(res)
# ri = next(res)  # 可以通过next()或.__next__来迭代生成器中的数据
# print(ri)
# for i in ri:  # 通过for循环遍历的是yield后面的数据
#     print(i)

# res2 = fun02()
# # 1、使用next进行迭代操作
# # print(next(res2))
# # 使用send进行迭代操作
# next(res2)
# print(res2.send("你好"))

# res3=fun03()
# next(res3)
# print(res3.send("天空"))
# print(res3.send("城市"))
# throw主动往生成器内部抛出异常
# res3.throw(ValueError)

